// const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const NodePolyfillWebpackPlugin = require("node-polyfill-webpack-plugin");
const webpackCommonRules = require("./webpack.rules.common");
const { merge } = require("webpack-merge");
// const path = require('path');
const path = require("path");
// const path = require('path')

module.exports = merge(webpackCommonRules, {
  mode: "development",
  entry: "./src/index.js",
  output: {
    filename: "static/js/[name].[contenthash].js",
    path: path.resolve(__dirname, "./dist"),
    // publicPath: './',
    clean: true, //
  },
  module: {
    rules: [
      // JavaScript
      {
        test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
        type: "asset/inline",
      },
      {
        test: /\.(scss|css)$/,
        use: [
          "style-loader",
          {
            loader: "css-loader",
            options: {
              importLoaders: 1,
            },
          },
          "postcss-loader",
        ],
      },
    ],
  },

  node: {
    global: true,
    __filename: false,
    __dirname: false,
    // fs:true,
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, "./src/index.html"),
    }),
    // new webpack.ProvidePlugin({
    //     process: 'process/browser', // 注意这里的路径，使用 "process/browser" 而非仅仅是 "process"
    //   }),
    new NodePolyfillWebpackPlugin(),
  ],
  optimization: {
    runtimeChunk: "single",
    splitChunks: {
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name: "vendors",
          chunks: "all",
        },
      },
    },
  },
  resolve: {
    extensions: [".js", ".tsx", ".ts"],
    alias: {
      "@": path.join(__dirname, "./src"),
      "@container": path.join(__dirname, "./src/container"),
      "base/intl": path.join(__dirname, "./src/utils/intl.js"),
    },
  },
});
